<!DOCTYPE html>
<html>
<head>
	<title></title>
	<script type="text/javascript">var price_total=new Array();var product_id=new Array();</script>
</head>
<body>
<form action="/test/order/index" method="post">
<table border="1"  style="px;width:500px;height: 200px;border-collapse: collapse;text-align: center;">
	<tr >
		
		<td>产品名字</td>
		<td>产品描述</td>
		<td>产品单价</td>
		<td>产品数量</td>
		<td>小计</td>
		<td>操作</td>

	</tr>
	{foreach name="list" item="val" key="i"}
	
	
	<tr name="product_list[{$i}]">
		
		<td name="product_name[{$i}]">{$val.product_name}</td>
		<td name="product_information[{$i}]">{$val.product_information}</td>
		<td id="product_price[{$i}]">{$val.product_price}</td>
		<td id="product_num[{$i}]"><span onclick="subtract{$i}(this)" >-</span><div id="test{$i}">{$val.product_num}</div><span onclick="plus{$i}(this)" >+</span></td>
		<td ><div name="product_total[{$i}]" id="product_total{$i}" >{$total[$i]}</div></td>
		
		<td><input type="checkbox" value="{$val.product_id}" name="order" onchange="get_productId()"></td>

		
	</tr>

<script type="text/javascript" src="/static/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
	
	price_total[{$i}]=$('#product_total{$i}').html();
	console.log(price_total);
	
	

	function plus{$i}(obj)
	{
		var product_price=document.getElementById("product_price[{$i}]").innerHTML;
		var count=$('#test{$i}').html();
		
		count++;
		$('#test{$i}').html(count);
		var total=product_price*count;

		console.log(total);

		price_total[{$i}]=total;
		
		$('#product_total{$i}').html(total);	
		//$('#product_total{$i}').val(total);
		//document.getElementById("product_total[{$i}]").innerHTML=total;
		


		
		
	};
	function subtract{$i}(obj)
	{
		var product_price=document.getElementById("product_price[{$i}]").innerHTML;
		var count=$('#test{$i}').html();
		if(count>0)
		{
			count--;
			$('#test{$i}').html(count);
			var total=product_price*count;
			console.log(total);
			price_total[{$i}]=total;
			$('#product_total{$i}').html(total);
			//$('#product_total{$i}').val(total);
	    }
		
		
	};
	
	
	function get_productId()
	{
				//total[{$i}]= document.getElementById("product_total[{$i}]").innerHTML;
		var c_box=document.getElementsByName("order");
		var c_length=c_box.length;
		for(var i=0;i<c_length;i++)
		{
			if(c_box[i].checked)

			{
				product_id[i]=c_box[i].value;

				//alert("值："+c_box[i].value+"的文本框被选中");
			}
			else
			{
				product_id[i]='';
			}

		


	    }

	console.log(product_id);
	$('#productId').val(product_id);	
	console.log($('#productId').val());
		
	};
	function count()
	{
        var cc=0;
        var c_box=document.getElementsByName("order");
		var c_length=c_box.length;
		for(var a=0;a<c_length;a++)
		{
			if(c_box[a].checked)
			{

			cc+= parseFloat(price_total[a]);
			
			}
			else
			{

			}


		}
		$('#order_total').html(cc);	
		$('#orderTotal').val(cc);
		var bc=$('#orderTotal').val(cc);
		

		
		
	}
	var t1=window.setInterval("count()",100);
	
</script>
    
	{/foreach}

<script type="text/javascript">


	/*function count()
	{
	            var cc=0;
	            var c_box=document.getElementsByName("order");
				var c_length=c_box.length;
				for(var a=0;a<c_length;a++)
				{
					if(c_box[a].checked)
					{
					cc+=parseFloat(document.getElementById("product_total"+a).value); 
					//var b=$("#product_total{a}").val()  
					}


				}
		$('#order_total').html(cc);	
		$.ajax({
			type:'post',
			url:'/test/order/ajax',
			data:{'cc':cc},
			dataType:'json',
	        success : function(ret){
	        	
	        	console.log(ret);
	        },
	        error : function(){ console.log(2222);}
		});		
	}
	var t1=window.setInterval("count()",100);
*/
	
</script>
	
</table>
<div id="order_total" style="font-size: 30px"></div>
<input type="hidden" name="orderTotal" id="orderTotal"/>
<input type="hidden" name="productId" id="productId">


<input type="submit" name="" value="提交购物车"/>
</form>

</body>
</html>